package com.akw.config;

import com.akw.bean.*;
//import com.alibaba.druid.FastsqlException;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

//@Import(FastsqlException.class)
@SpringBootConfiguration
@EnableConfigurationProperties({Sheep.class})
public class AppConfig {

    @Bean
    @ConfigurationProperties(prefix = "pig")
    public Pig pig() {
        return new Pig();
    }

    @ConditionalOnClass(name="com.alibaba.druid.FastsqlException")
    @Bean
    public Cat cat01() {
        return new Cat(1L, "AKW");
    }

    @ConditionalOnMissingClass(value = "com.alibaba.druid.FastsqlException")
    @Bean
    public Dog dog01() {
        return new Dog(1L, "AK");
    }

    @ConditionalOnBean(value = Dog.class)
    @Bean
    public User zhangsan() {
        return new User(1L, "张三");
    }

    @ConditionalOnMissingBean(value = Dog.class)
    @Bean
    public User lisi() {
        return new User(2L, "李四");
    }
}
